package dfs;

import entity.tree.TreeNode;

import java.util.Objects;

public class leetcode872叶子相似的树 {
    public boolean leafSimilar(TreeNode root1, TreeNode root2) {
        return Objects.equals(dfs(root1), dfs(root2));
    }

    // 加点原因：
    // [3,5,1,6,2,9,8,null,null,7,4]
    // [3,5,1,6,7,4,2,null,null,null,null,null,null,9,8]
    // 上边671498，代表的数字是 6,7,14,9,8。下边671498，代表的数字是 6,71,4,9,8
    public String dfs(TreeNode root) {
        String str = "";
        if (root == null) {
            return str;
        }
        if (root.left == null && root.right == null) {
            str += root.val + ".";
        }
        str += dfs(root.left);
        str += dfs(root.right);
        return str;
    }
}
